package com.sh_rw.label.common.parser;


import com.sh_rw.label.bean.BaseLabel;
import com.sh_rw.label.bean.StatusBean;
import com.sh_rw.label.listener.ParserListener;
import com.sh_rw.label.utils.HexUtils;

/**
 * Created by rw-duke on 2018/4/4.
 */

public class _18Parser extends _ReplyParser {

    private int type;
    private int count;
    private int labelIndex;


    @Override
    public void onLabelParser(byte[] data, ParserListener listener) {
        if (check(data)) {
            count = data[23] & 0xff;
//            LabelBean labelBean;
            BaseLabel label;
            StatusBean statusBean;
            for (int i = 0; i < count; i++) {
                labelIndex = 14 * i;
                label = new BaseLabel();
                label.setLabelType(18);
                statusBean = new StatusBean(data[27 + labelIndex]);
                label.set_id(data[24+labelIndex],data[25 + labelIndex], data[26 + labelIndex]);
                label.setStatus(statusBean);
                label.setActiId1(data[28 + labelIndex], data[29 + labelIndex]);
                label.setActiRssi1(data[30 + labelIndex]);
                label.setActiId2(data[31 + labelIndex], data[32 + labelIndex]);
                label.setHeartRate(data[33 + labelIndex]);
                label.setActCount(data[34 + labelIndex]);
                label.setSendCount(data[35 + labelIndex]);
                label.setHfRssi1(data[36 + labelIndex]);
                label.setHfRssi2(data[37 + labelIndex]);

//                labelBean.setId(HexUtils.toHexString(data[24 + labelIndex], data[25 + labelIndex], data[26 + labelIndex]));
//                labelBean.setStatus(statusBean);
//                labelBean.setAct_id1(HexUtils.toHexString(data[28 + labelIndex], data[29 + labelIndex]));
//                labelBean.setAct_rssi1(HexUtils.toHexString(data[30 + labelIndex]));
//                labelBean.setAct_id2(HexUtils.toHexString(data[31 + labelIndex], data[32 + labelIndex]));
//                labelBean.setHeartRate(HexUtils.toHexString(data[33 + labelIndex]));
//                labelBean.setActCount(HexUtils.toHexString(data[34 + labelIndex]));
//                labelBean.setSendCount(HexUtils.toHexString(data[35 + labelIndex]));
//                labelBean.setHf_rssi1(HexUtils.toHexString(data[36 + labelIndex]));
//                labelBean.setHf_rssi2(HexUtils.toHexString(data[37 + labelIndex]));
                listener.onLabelCallback(1, label);
            }
        } else {
//            listener.onError(new );
        }
//        listener.onLabelCallback(0x01,);
    }

    @Override
    public boolean check(byte[] data) {
//        boolean check = CheckUtils.checkPacket(data);
//        boolean check2 = (data[13] & 0xff) == 18;
        return (data[13] & 0xff) == 18;
    }


}
